package cn.hfatec.shms.web.cw.cwHb.service;

import java.util.Calendar;
import java.util.List;
import java.util.HashMap;


import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.hfatec.base.BaseDao;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.shms.web.cw.cwHb.model.CwHb;
import cn.hfatec.shms.web.cw.cwHb.dao.CwHbDao;
import cn.hfatec.shms.web.cw.cwHb.model.CwHbParams;

import javax.annotation.Resource;


/**
 * @author hfatec
 * @version 1.0
 *          <p/>
 *          the JAVA code is generate by middlegen
 */
@Service("CwHbService")
public class CwHbService {

    public static final String BEAN_ID = "CwHbService";

    //注入Dao层
    @Resource(name = "CwHbDao")
    private CwHbDao cwHbDao;

    //注入BaseDao
    @Resource(name = "BaseDao")
    private BaseDao baseDao;

    /**
     * 查询数据
     *
     * @param cwHbParams
     * @param page
     */
    @Transactional
    public Table queryCwHbTable(CwHbParams cwHbParams, Page page) {
        Calendar now = Calendar.getInstance();
        if (cwHbParams.getYear() == null) {
            cwHbParams.setYear(now.get(Calendar.YEAR));
        }
        if (cwHbParams.getMonth() == null) {
            cwHbParams.setMonth(now.get(Calendar.MONTH));
        }
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", cwHbParams);
        return baseDao.queryTableByPage("queryCwHb", params, page);
    }

    /**
     * 查询数据
     *
     * @param cwHbParams
     * @param page
     */
    @Transactional
    public Table queryCwHbTableRj(CwHbParams cwHbParams, Page page) {
        Calendar now = Calendar.getInstance();
        if (cwHbParams.getMonth() == null) {
            cwHbParams.setMonth(now.get(Calendar.MONTH));
        }
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", cwHbParams);
        return baseDao.queryTableByPage("queryCwHbRj", params, page);
    }
    /**
     * 查询数据
     *
     * @param cwHbParams
     * @param page
     */
    @Transactional
    public Table queryCwHbTableRjMx(CwHbParams cwHbParams, Page page) {
        Calendar now = Calendar.getInstance();
            HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", cwHbParams);
        return baseDao.queryTableByPage("queryCwHbRjMx", params, page);
    }



    /**
     * 查询数据
     *
     * @param cwHbParams
     * @param page
     */
    @Transactional
    public Table queryCwHbTableFy(CwHbParams cwHbParams, Page page) {
        Calendar now = Calendar.getInstance();
        if (cwHbParams.getMonth() == null) {
            cwHbParams.setMonth(now.get(Calendar.MONTH));
        }
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", cwHbParams);
        return baseDao.queryTableByPage("queryCwHbFy", params, page);
    }
    /**
     * 查询数据
     *
     * @param cwHbParams
     * @param page
     */
    @Transactional
    public Table queryCwHbTableFyMx(CwHbParams cwHbParams, Page page) {
        Calendar now = Calendar.getInstance();
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", cwHbParams);
        return baseDao.queryTableByPage("queryCwHbFyMx", params, page);
    }
    /**
     * 查询数据
     *
     * @param cwHbParams
     * @param page
     */
    @Transactional
    public Table queryCwHbTableMy(CwHbParams cwHbParams, Page page) {
        Calendar now = Calendar.getInstance();
        if (cwHbParams.getMonth() == null) {
            cwHbParams.setMonth(now.get(Calendar.MONTH));
        }
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", cwHbParams);
        return baseDao.queryTableByPage("queryCwHbMy", params, page);
    }
    /**
     * 查询数据
     *
     * @param cwHbParams
     * @param page
     */
    @Transactional
    public Table queryCwHbTableMyMx(CwHbParams cwHbParams, Page page) {
        Calendar now = Calendar.getInstance();
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", cwHbParams);
        return baseDao.queryTableByPage("queryCwHbMyMx", params, page);
    }


    /**
     * 插入数据
     *
     * @param cwHb
     */
    @Transactional
    public void saveCwHb(CwHb cwHb) {
        if (cwHb.getId() != null) {
            CwHb result = getCwHb(cwHb.getId());
            if (result != null) {
                cwHbDao.update(cwHb);
            } else {
                cwHbDao.insert(cwHb);
            }
        } else {
            cwHbDao.insert(cwHb);
        }
    }

    /**
     * 删除数据
     *
     * @param id
     */
    @Transactional
    public void deleteCwHb(Integer id) {

        cwHbDao.delete(id);
    }

    /**
     * 删除数据
     *
     * @param cwHbList
     */
    @Transactional
    public void deleteCwHbBatch(List<String> cwHbList) {
        for (String id : cwHbList) {
            deleteCwHb(Integer.valueOf(id));
        }
    }

    /**
     * 根据ID获取数据
     *
     * @param id
     */
    @Transactional
    public CwHb getCwHb(Integer id) {

        return cwHbDao.getCwHbById(id);
    }
}